local gatedLaunch, _ = string.find(ngx.var.uri, '/gated_launch')
local beta_tenant_ids_key = ngx.var.redis_region .. '_' .. ngx.var.beta_tenant_ids
--如果是灰度发布请求
if gatedLaunch then 
  local redis = require 'redis_iresty'
  local red = redis:new()
  local existedTenants, _  = string.find(ngx.var.uri, '/get_existed_tenants')

  if existedTenants then
    local tenantIds = red:get(beta_tenant_ids_key)
    ngx.say(tenantIds)
    return
  end

  local updateTenants, _ = string.find(ngx.var.uri, '/update_tenants')

  if updateTenants then 
    local postArgs = ngx.req.get_post_args()
    local tenantIds = postArgs.tenantIds
    local ok, err = red:set(beta_tenant_ids_key, tenantIds)
    if not ok then 
      ngx.say("fail to update tenants" .. beta_tenant_ids_key .. "--" .. tenantIds, err)
    else 
      ngx.say(tenantIds)
    end
    return
  end

  return 
end

